# Conformance testing for Protobuf.

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", "cc_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")

exports_files([
    "conformance_test_runner.sh",
    "failure_list_java.txt",
    "failure_list_java_lite.txt",
    "text_format_failure_list_java.txt",
    "text_format_failure_list_java_lite.txt",
])

cc_proto_library(
    name = "test_messages_proto2_proto_cc",
    deps = ["//:test_messages_proto2_proto"],
)

cc_proto_library(
    name = "test_messages_proto3_proto_cc",
    deps = ["//:test_messages_proto3_proto"],
)

proto_library(
    name = "conformance_proto",
    srcs = ["conformance.proto"],
    visibility = ["//visibility:public"],
)

cc_proto_library(
    name = "conformance_proto_cc",
    deps = [":conformance_proto"],
)

java_proto_library(
    name = "conformance_java_proto",
    visibility = [
        "//java:__subpackages__",
    ],
    deps = [":conformance_proto"],
)

java_lite_proto_library(
    name = "conformance_java_proto_lite",
    visibility = [
        "//java:__subpackages__",
    ],
    deps = [":conformance_proto"],
)

cc_library(
    name = "jsoncpp",
    srcs = ["third_party/jsoncpp/jsoncpp.cpp"],
    hdrs = ["third_party/jsoncpp/json.h"],
    includes = ["."],
)

cc_library(
    name = "conformance_test",
    srcs = [
        "conformance_test.cc",
        "conformance_test_runner.cc",
    ],
    hdrs = [
        "conformance_test.h",
    ],
    includes = ["."],
    deps = [":conformance_proto_cc"],
)

cc_library(
    name = "binary_json_conformance_suite",
    srcs = ["binary_json_conformance_suite.cc"],
    hdrs = ["binary_json_conformance_suite.h"],
    deps = [
        ":conformance_test",
        ":jsoncpp",
        ":test_messages_proto2_proto_cc",
        ":test_messages_proto3_proto_cc",
    ],
)

cc_library(
    name = "text_format_conformance_suite",
    srcs = ["text_format_conformance_suite.cc"],
    hdrs = ["text_format_conformance_suite.h"],
    deps = [
        ":conformance_test",
        ":test_messages_proto2_proto_cc",
        ":test_messages_proto3_proto_cc",
    ],
)

cc_binary(
    name = "conformance_test_runner",
    srcs = ["conformance_test_main.cc"],
    visibility = ["//visibility:public"],
    deps = [
        ":binary_json_conformance_suite",
        ":conformance_test",
        ":text_format_conformance_suite",
    ],
)

java_binary(
    name = "conformance_java",
    srcs = ["ConformanceJava.java"],
    main_class = "ConformanceJava",
    visibility = [
        "//java:__subpackages__",
    ],
    deps = [
        ":conformance_java_proto",
        "//:protobuf_java",
        "//:protobuf_java_util",
        "//:test_messages_proto2_java_proto",
        "//:test_messages_proto3_java_proto",
    ],
)

java_binary(
    name = "conformance_java_lite",
    srcs = ["ConformanceJavaLite.java"],
    main_class = "ConformanceJavaLite",
    visibility = [
        "//java:__subpackages__",
    ],
    deps = [
        ":conformance_java_proto_lite",
        "//:protobuf_java_util",
        "//:protobuf_javalite",
        "//:test_messages_proto2_java_proto_lite",
        "//:test_messages_proto3_java_proto_lite",
    ],
)

filegroup(
    name = "all_files",
    srcs = glob(["**/*"]),
    visibility = ["//:__pkg__"],
)

pkg_files(
    name = "dist_files",
    srcs = glob(
        ["**/*"],
        exclude = [
            # The following are not in autotools dist:
            "conformance/autoload.php",
            "conformance/conformance_nodejs.js",
            "conformance/conformance_test_runner.sh",
            "conformance/failure_list_java_lite.txt",
            "conformance/failure_list_jruby.txt",
            "conformance/text_format_failure_list_*.txt",
            "conformance/update_failure_list.py",
        ],
    ),
    strip_prefix = strip_prefix.from_root(""),
    visibility = ["//pkg:__pkg__"],
)
